package May;
//多态的几种实现方法
//

class Animal {
    public int age;
    public String name;

    public Animal (int age, String name) {
        this.age = age;
        this.name = name;
    }

    public void eat () {
        System.out.println (name + "正在吃");
    }

    @Override
    public String toString () {
        return "Animal{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}

class Dog extends Animal {

    public Dog (int age, String name) {
        super (age, name);
    }

    public void wang () {
        System.out.println (name + "汪汪");
    }

}


public class Learn_5_1 {
    //实现多态的几种方式
    //向上转型（不能调用子类中特有的方法）
    //1.直接赋值
    //2.传参
    //3.返回值


    public static void main (String[] args) {
        Animal an = new Dog (10, "huang");
        Dog dog = new Dog (10, "狗");
        //无论参数是animal还是Dog，都可以调用该函数
        func1 (dog);

        func1 (an);
        Animal bn = func2 ();
    }

    //static修饰后代表全局的意思
    public static void func1 (Animal an) {
    }

    public static Animal func2 () {
        return new Dog (10, "hong");
    }
}
